package stool.compositepattern;

import java.util.ArrayList;
import java.util.List;

import static stool.compositepattern.StringUtils.formatStr;

/**
 * @Author Felix YF Dong
 * @Date 2021/5/11
 */
public class ConcreteCompany extends Company{

    private List<Company> childrens = new ArrayList<>();

    public ConcreteCompany(String name) {
        super(name);
    }

    @Override
    public void create(Company company) {
        childrens.add(company);
    }

    @Override
    public void find(int depth) {
        System.out.println(formatStr("-", depth)+ super.getName());
        childrens.forEach(children -> {
            children.find(depth + 2);
        });
    }

    @Override
    public void delete(Company company) {
        childrens.remove(company);
    }


    @Override
    public void lineOfDuty() {
        childrens.forEach(Company::lineOfDuty);
    }


}
